package com.ycsj.goldmedalnewconcept.activity;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.ImageView;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.onekeyshare.ShareContentCustomizeCallback;
import cn.sharesdk.sina.weibo.SinaWeibo;

import com.mob.MobSDK;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.bean.ClassThirdListInfo;

public class ZhiboOverActivity extends BaseJpStarActivity implements OnClickListener {

	protected ArrayList<ClassThirdListInfo> list = new ArrayList<ClassThirdListInfo>();
	private ImageView iv_share;
	private ImageView iv_back;
	private WebView mWebView;
	private String URL;
	private String v_id;
	private String title;
	private String time;
	private String picurl;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zhiboover);

		getData();
		initViews();
		initWebView();
		initListener();
	};

	private void getData() {
		// TODO Auto-generated method stub
		URL = getIntent().getStringExtra("url");
		v_id = getIntent().getStringExtra("v_id");
		title = getIntent().getStringExtra("title");
		time = getIntent().getStringExtra("time");
		picurl = getIntent().getStringExtra("picurl");
	}

	private void initListener() {
		// TODO Auto-generated method stub
		iv_back.setOnClickListener(this);
		iv_share.setOnClickListener(this);
	}

	private void initViews() {
		mWebView = (WebView) findViewById(R.id.webview_player);
		iv_share = (ImageView) findViewById(R.id.iv_share);
		iv_back = (ImageView) findViewById(R.id.iv_back);
	}

	@SuppressLint("NewApi")
	private void initWebView() {
		
		WebSettings settings = mWebView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setPluginState(PluginState.ON);
		// settings.setPluginsEnabled(true);
		settings.setAllowFileAccess(true);
		settings.setLoadWithOverviewMode(true);
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){  
			settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  
	     } 
		
		
//		WebSettings settings = mWebView.getSettings();
//		settings.setJavaScriptEnabled(true);
//		settings.setJavaScriptCanOpenWindowsAutomatically(true);
//		settings.setPluginState(PluginState.ON);
//		// settings.setPluginsEnabled(true);
//		settings.setAllowFileAccess(true);
//		settings.setLoadWithOverviewMode(true);

//		mWebView.loadUrl("https://v.qq.com/iframe/player.html?vid=o0525kg25zx&tiny=0&auto=0");
//		mWebView.loadUrl("https://v.qq.com/iframe/player.html?vid=b03570x0gs6&tiny=0&auto=0");
		mWebView.loadUrl(URL);
		Log.e("URL", URL);
		mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// 返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
				view.loadUrl(url);
				return true;
			}
		});
	}

	
	
	@Override
	public void onPause() {
	    super.onPause();
	    mWebView.onPause();
	    mWebView.pauseTimers();
	}

	@Override
	public void onResume() {
	    super.onResume();
	    mWebView.resumeTimers();
	    mWebView.onResume();
	}


	@Override
	protected void onDestroy() {
		mWebView.destroy();
		mWebView = null;
	    super.onDestroy();
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_back:
			finish();
			break;
		case R.id.iv_share:
			clickShare(v);
			break;
		}
	}
	
	
	
	private void clickShare(View v) {

		// TODO Auto-generated method stub
		MobSDK.init(ZhiboOverActivity.this, "12c24ea0b59b0",
				"aae63565fbd69b1acbfcdd0d5ac0b35c");
		OnekeyShare oks = new OnekeyShare();
		// 关闭sso授权
		oks.disableSSOWhenAuthorize();
		oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {

			@Override
			public void onShare(Platform platform, ShareParams paramsToShare) {
				if (SinaWeibo.NAME.equals(platform.getName())) {
					paramsToShare.setTitle(getString(R.string.share));
					// titleUrl是标题的网络链接，仅在人人网和QQ空间使用
					String url = "http://m.moregolden.com:36356/videoLive/video.html?vid="
							+ v_id;

					// String title = title;
					int unicodeJoy = 0x1F44D;
					String emojiString = new String(Character
							.toChars(unicodeJoy));
					paramsToShare
							.setTitleUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);
					// paramsToShare.setTitleUrl("http://m.moregolden.com:36356/redBag/redBag.html?rid="+redid);
					paramsToShare.setTitle(title);
					// text是分享文本，所有平台都需要这个字段
					paramsToShare.setText("金牌新概念邀您收听直播\n" + "时间：" + time);
					// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
					// oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
					paramsToShare.setImageUrl(picurl);
					// paramsToShare.setImageData(mBitmap);
					// url仅在微信（包括好友和朋友圈）中使用
					paramsToShare
							.setUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);
					// paramsToShare.setUrl("http://m.moregolden.com:36356/redBag/redBag.html?rid="+redid);
					// comment是我对这条分享的评论，仅在人人网和QQ空间使用
					paramsToShare.setComment("");
					// site是分享此内容的网站名称，仅在QQ空间使用
					// paramsToShare.setSite(getString(R.string.app_name));
					paramsToShare.setSite("金牌君");
					// siteUrl是分享此内容的网站地址，仅在QQ空间使用
					paramsToShare
							.setSiteUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);
					// paramsToShare.setSiteUrl("http://m.moregolden.com:36356/redBag/redBag.html?rid="+redid);

				} else {
					paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
					paramsToShare.setTitle(getString(R.string.share));
					// titleUrl是标题的网络链接，仅在人人网和QQ空间使用
					paramsToShare
							.setTitleUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);
					// paramsToShare.setTitleUrl("http://m.moregolden.com:36356/redBag/redBag.html?rid="+redid);
					paramsToShare.setTitle(title);
					// text是分享文本，所有平台都需要这个字段
					paramsToShare.setText("金牌新概念邀您收听直播\n" + "时间：" + time);
					// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
					// oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
					paramsToShare.setImageUrl(picurl);

					// paramsToShare.setImageData(mBitmap);
					// url仅在微信（包括好友和朋友圈）中使用
					paramsToShare
							.setUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);
					// paramsToShare.setUrl("http://m.moregolden.com:36356/redBag/redBag.html?rid="+redid);
					// comment是我对这条分享的评论，仅在人人网和QQ空间使用
					paramsToShare.setComment("");
					// site是分享此内容的网站名称，仅在QQ空间使用
					paramsToShare.setSite("金牌君");
					// paramsToShare.setSite(getString(R.string.app_name));
					// siteUrl是分享此内容的网站地址，仅在QQ空间使用
					paramsToShare
							.setSiteUrl("http://m.moregolden.com:36356/videoLive/video.html?vid="
									+ v_id);

				}
			}
		});

		// 启动分享GUI
		oks.show(this);
	}

}
